// pages/goods_list/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs: [{
      id: 0,
      value: "综合",
      isActive: true
    }, 
    {
      id: 1,
      value: "销量",
      isActive: false
    }, 
    {
      id: 2,
      value: "价格",
      isActive: false
    }],

    list: {
      "total": 57445,
      "pagenum": 1,
      "goods": [{
        "goods_id": 57444,
        "cat_id": 9,
        "goods_name": "创维（Skyworth）42X6 42英寸10核智能酷开网络平板液晶电视（黑色）",
        "goods_price": 1899,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "http://image2.suning.cn/uimg/b2c/newcatentries/0070078057-000000000634917020_1_800x800.jpg",
        "goods_small_logo": "http://image2.suning.cn/uimg/b2c/newcatentries/0070078057-000000000634917020_1_400x400.jpg",
        "add_time": 1516663280,
        "upd_time": 1516663280,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      },{
        "goods_id": 57442,
        "cat_id": 9,
        "goods_name": "创维彩电40G6A",
        "goods_price": 2999,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "http://image1.suning.cn/uimg/b2c/newcatentries/0000000000-000000000601395527_1_800x800.jpg",
        "goods_small_logo": "http://image1.suning.cn/uimg/b2c/newcatentries/0000000000-000000000601395527_1_400x400.jpg",
        "add_time": 1516663277,
        "upd_time": 1516663277,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57441,
        "cat_id": 9,
        "goods_name": "创维(Skyworth) G7 4K超高清彩电HDR 智能网络液晶平板电视(玫瑰金) 65G7 (65英寸)",
        "goods_price": 9699,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "http://image2.suning.cn/uimg/b2c/newcatentries/0000000000-000000000168415104_1_800x800.jpg",
        "goods_small_logo": "http://image2.suning.cn/uimg/b2c/newcatentries/0000000000-000000000168415104_1_400x400.jpg",
        "add_time": 1516663273,
        "upd_time": 1516663273,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57440,
        "cat_id": 9,
        "goods_name": "创维彩电55G3",
        "goods_price": 4699,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000632066713_1_800x800.jpg",
        "goods_small_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000632066713_1_400x400.jpg",
        "add_time": 1516663269,
        "upd_time": 1516663269,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57439,
        "cat_id": 9,
        "goods_name": "创维电视55G720S 55英寸4色4K 23核智能彩电网络液晶平板电视",
        "goods_price": 4999,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000611474169_1_800x800.jpg",
        "goods_small_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000611474169_1_400x400.jpg",
        "add_time": 1516663265,
        "upd_time": 1516663265,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57438,
        "cat_id": 9,
        "goods_name": "创维（Skyworth）55H9A 55英寸超薄 全面屏 4K超高清智能电视(黑色)",
        "goods_price": 3999,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "http://image4.suning.cn/uimg/b2c/newcatentries/0000000000-000000000185518945_2_800x800.jpg",
        "goods_small_logo": "http://image4.suning.cn/uimg/b2c/newcatentries/0000000000-000000000185518945_2_400x400.jpg",
        "add_time": 1516663261,
        "upd_time": 1516663261,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57437,
        "cat_id": 9,
        "goods_name": "创维（Skyworth）55V6 55英寸 4色4K超高清 18核 智能网络液晶电视 银色",
        "goods_price": 3099,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "http://image3.suning.cn/uimg/b2c/newcatentries/0070078057-000000000136928577_1_800x800.jpg",
        "goods_small_logo": "http://image3.suning.cn/uimg/b2c/newcatentries/0070078057-000000000136928577_1_400x400.jpg",
        "add_time": 1516663258,
        "upd_time": 1516663258,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57436,
        "cat_id": 9,
        "goods_name": "创维(Skyworth) 43M9 43英寸 4K超高清智能网络LED液晶平板电视",
        "goods_price": 2399,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "http://image4.suning.cn/uimg/b2c/newcatentries/0070078057-000000000751129836_1_800x800.jpg",
        "goods_small_logo": "http://image4.suning.cn/uimg/b2c/newcatentries/0070078057-000000000751129836_1_400x400.jpg",
        "add_time": 1516663255,
        "upd_time": 1516663255,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57435,
        "cat_id": 9,
        "goods_name": "创维(Skyworth) G7 4K超高清彩电HDR 智能网络液晶平板电视(玫瑰金) 50G7 (50英寸)",
        "goods_price": 4999,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "http://image4.suning.cn/uimg/b2c/newcatentries/0000000000-000000000174647582_1_800x800.jpg",
        "goods_small_logo": "http://image4.suning.cn/uimg/b2c/newcatentries/0000000000-000000000174647582_1_400x400.jpg",
        "add_time": 1516663249,
        "upd_time": 1516663249,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57434,
        "cat_id": 9,
        "goods_name": "创维（Skyworth）60V8E 60英寸 4色4K 21核金属机身超高清智能网络液晶电视（金色）",
        "goods_price": 4499,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "http://image4.suning.cn/uimg/b2c/newcatentries/0070078057-000000000154099975_1_800x800.jpg",
        "goods_small_logo": "http://image4.suning.cn/uimg/b2c/newcatentries/0070078057-000000000154099975_1_400x400.jpg",
        "add_time": 1516663246,
        "upd_time": 1516663246,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57433,
        "cat_id": 9,
        "goods_name": "创维(skyworth) 55V8E 55英寸 4K超高清HDR纤薄全金属机身智能酷开网络液晶电视",
        "goods_price": 3299,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "http://image3.suning.cn/uimg/b2c/newcatentries/0070078057-000000000153983248_1_800x800.jpg",
        "goods_small_logo": "http://image3.suning.cn/uimg/b2c/newcatentries/0070078057-000000000153983248_1_400x400.jpg",
        "add_time": 1516663242,
        "upd_time": 1516663242,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57432,
        "cat_id": 9,
        "goods_name": "创维(Skyworth) 58V6 58英寸 4K超高清智能网络LED液晶平板电视",
        "goods_price": 3299,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "http://image2.suning.cn/uimg/b2c/newcatentries/0000000000-000000000137137563_1_800x800.jpg",
        "goods_small_logo": "http://image2.suning.cn/uimg/b2c/newcatentries/0000000000-000000000137137563_1_400x400.jpg",
        "add_time": 1516663239,
        "upd_time": 1516663239,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57431,
        "cat_id": 9,
        "goods_name": "创维（Skyworth）55E5 55吋4K超高清智能电视",
        "goods_price": 2956,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "http://image1.suning.cn/uimg/b2c/newcatentries/0000000000-000000000147767325_1_800x800.jpg",
        "goods_small_logo": "http://image1.suning.cn/uimg/b2c/newcatentries/0000000000-000000000147767325_1_400x400.jpg",
        "add_time": 1516663236,
        "upd_time": 1516663236,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57430,
        "cat_id": 9,
        "goods_name": "创维（Skyworth）65M9 65英寸15核HDR 4K超高清智能电视",
        "goods_price": 0,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "",
        "goods_small_logo": "",
        "add_time": 1516663233,
        "upd_time": 1516663233,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57429,
        "cat_id": 9,
        "goods_name": "创维（Skyworth）50M9 50英寸15核HDR 4K超高清智能电视",
        "goods_price": 2603,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "",
        "goods_small_logo": "",
        "add_time": 1516663213,
        "upd_time": 1516663213,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57428,
        "cat_id": 9,
        "goods_name": "创维.PPTV W42S 42英寸 全高清智能网络LED液晶平板电视",
        "goods_price": 1799,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "http://image2.suning.cn/uimg/b2c/newcatentries/0000000000-000000000721208036_1_800x800.jpg",
        "goods_small_logo": "http://image2.suning.cn/uimg/b2c/newcatentries/0000000000-000000000721208036_1_400x400.jpg",
        "add_time": 1516663210,
        "upd_time": 1516663210,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57427,
        "cat_id": 9,
        "goods_name": "创维(Skyworth) 32X6 32英寸 高清智能网络LED液晶平板电视",
        "goods_price": 1201,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "http://image4.suning.cn/uimg/b2c/newcatentries/0000000000-000000000775604287_1_800x800.jpg",
        "goods_small_logo": "http://image4.suning.cn/uimg/b2c/newcatentries/0000000000-000000000775604287_1_400x400.jpg",
        "add_time": 1516663203,
        "upd_time": 1516663203,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }, {
        "goods_id": 57426,
        "cat_id": 9,
        "goods_name": "创维（Skyworth）55M9 55英寸15核HDR 4K超高清智能电视M7",
        "goods_price": 2999,
        "goods_number": 100,
        "goods_weight": 100,
        "goods_big_logo": "",
        "goods_small_logo": "",
        "add_time": 1516663200,
        "upd_time": 1516663200,
        "hot_mumber": 0,
        "is_promote": false,
        "cat_one_id": 1,
        "cat_two_id": 3,
        "cat_three_id": 9
      }]
    },

      goodsList:[]
  },

  QueryParams:{
    query:"",
    cid:"",
    pagenum:1,
    pagesize:10
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.QueryParams.cid = options.cid||"";
    this.QueryParams.query = options.query||"";
    this.getGoodsList();
  },

  //异步请求获取列表数据
  async getGoodsList(){
    
    const res = this.data.list; 
    const total = res.total;
    //计算总页数
    this.totalPages= Math.ceil(total/this.QueryParams.pagesize);
    this.setData({
      goodsList:res
    })
     //关闭下拉刷新的窗口,很快刷新
    wx.stopPullDownRefresh();
    //下一页刷新
    // this.setData({
    //   goodsList:[...this.data.getGoodsList,...res.goods]
    // })
  },

 
  
  //标题点击事件
  handleTabsItemChange(e) {
    //获取被点击的标题
    const {
      index
    } = e.detail;
    //修改原数组
    let {
      tabs
    } = this.data;
    tabs.forEach((v, i) => i === index ? v.isActive = 'true' : v.isActive = false);
    this.setData({
      tabs
    })
  },
  ///页面触底
  // onReachBootom(){
  //   if(this.QueryParams.pagenum>=this.totalPages){
  //     wx.showToast({
  //       title: '没有下一页数据了！',
  //     })
  //   }else{
  //     this.QueryParams.pagenum++;
  //     this.getGoodsList();
  //   }
  // },

  //下拉刷新事件
  onPullDownRefresh(){
    this.setData({
      goodsList:[]
    })
    //重置页码
    //重新发送请求
    this.getGoodsList();
  }
})